//
// Created by liuhuan on 2022/4/29.
//

#ifndef RUIYAN_PTZ_GNDCONTROL_H
#define RUIYAN_PTZ_GNDCONTROL_H

#include <string>
#include "define/DataDefine.h"
#include "utils/UDPClient.h"
#include <vector>
#include <functional>
#include <iostream>
#include <thread>
#include "define/InterDataDefine.h"
#include "callback/CallBack.h"
class GndControl {
public:
    static GndControl *getInstance() {
        static GndControl control;
        return &control;
    }

    void Start(const std::string &ip, const int &port);

    void Stop();

    void QuerySetDev();

    void QueryAlgParams(unsigned char devNo);

    void QueryTrackPtzPid();

    void PtzMove(GndToSkyPtzTypeEnum ptzType, unsigned char direction, unsigned short angle,
                 unsigned char speed);

    void ZoomAction(unsigned char devNo, unsigned char direction);

    void TrackAction(unsigned char devNo, BoundingBox box);

    void SetPtzPID(PIDInfo info, GndToSkyPtzPIDEnum type);

    void SetDetectParams(DetectParams params, unsigned char devNo);

    void SetTrackParams(TrackParams params, unsigned char devNo);

    void SetOneShot(std::string imgPath, unsigned char devNo);


private:
    void RecvData(char *data, size_t nLen);

    unsigned short getCrc(char *data, int len);

    static void *startSendInfo(void *pArgs);

    void sendInfo();

    void _returnDetectInfo(char *data, size_t nLen);

    void _returnBaseInfo(char *data, size_t nLen);

    void _returnDevInfo(char *data, size_t nLen);

    void _returnTrackInfo(char *data, size_t nLen);

    void _returnPtzPidInfo(char *data, size_t nLen);

    void _returnAlgParamsInfo(char *data, size_t nLen);

private:
    bool m_isStart = false;
    UdpClient *udpClient;
    std::thread *m_thread;
};


#endif //RUIYAN_PTZ_GNDCONTROL_H
